import 'package:flutter/widgets.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:imperius_insights/portal/state/indicator/indicator.dart';
import 'package:imperius_insights/portal/widgets/error.dart';
import 'package:imperius_insights/portal/widgets/placeable_widget.dart';
import 'package:imperius_insights/treaty/dimensions.dart';
import 'package:imperius_insights/treaty/palette.dart';

Widget makeIndicatable<T>(
    IndicatorState<T> indicator,
    Function onRefresh,
    Widget Function(BuildContext context, IndicatorState<T> indicator)
        contentBuilder) {
  return PlaceableWidget<T>(
      indicatorState: indicator,
      loadingWidgetBuilder: (context, indicator) {
        return ConstrainedBox(
          constraints: BoxConstraints(minHeight: 250),
          child: Center(
              child: SpinKitWave(
                  color: palette.theme, size: layoutDimensions.indicatorSize)),
        );
      },
      errorWidgetBuilder: (_, indicatorState) {
        return ConstrainedBox(
            constraints: BoxConstraints(minHeight: 250),
            child: Center(
              child: NetworkErrorWidget(onRefresh),
            )
        );
      },
      contentBuilder: (context, indicator) {
        return contentBuilder(context, indicator);
      });
}
